<%--
  Created by IntelliJ IDEA.
  User: 联想小鑫
  Date: 2021/11/15
  Time: 19:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.8.2.min.js"></script>
    <script src="js/fileupload.js"></script>
    <script src="My97DatePicker/WdatePicker.js"></script>
    <link rel="stylesheet" href="css/img.css">
</head>
<body>
<form enctype="multipart/form-data">
    商品名称: <input type="text" name="sid" id="sid" value="${param.id}"> <br>
    商品名称: <input type="text" name="sname" id="sname"> <br>
    商品编号: <input type="text" name="card" id="card"> <br>
    商品品牌: <select name="sbrandId" id="sbrandId">
    <option value="">请选择商品品牌</option>
</select><br>
    规格型号: <textarea name="sstyle" id="sstyle" cols="30" rows="10" placeholder="请输入规格型号"></textarea><br>
    价格: <input type="text" name="sprice" id="sprice"> <br>
    上架时间: <input type="text" name="stime"  onclick="WdatePicker()" id="stime"> <br>
    图片: <div class="photoUpLoad" >
    <input type="file"   class="photo" name="photo" accept="image/*"><span class="cross">+</span>
    <img src="" alt="" class="photoEcho">
</div><br>
</form>
<button id="add">修改</button>
</body>
<script>
    $(function () {
        $.ajax({
            url:"findgoods.do",
            data: {"id":$("#sid").val()},
            dataType:"json",
            type:"post",
            success:function (a) {
                console.log(a);
                $("#sname").val(a.sname);
                $("#card").val(a.card);
                $("#sbrandId").val(a.sbrandId);
                $("#sstyle").val(a.sstyle);
                $("#sprice").val(a.sprice);
                $("#stime").val(a.stime);
                $(".photoEcho").prop("src",a.pic);
            }
        })
        $.ajax({
            async:false,
            url:"findallbid.do",
            dataType:"json",
            type:"post",
            success:function (a) {
                for (let i in a) {
                    $("#sbrandId").append(
                        " <option value='"+a[i].bid+"'>"+a[i].brandName+"</option>"
                    )
                }
            }
        })
    })
    $("#add").click(function () {
        var formData=new FormData($("form")[0]);
        $.ajax({
            url: "updGoods.do",
            data:formData,
            dataType: "json",
            type:"post",
            success:function (a) {
                if (a > 0) {
                    alert("修改成功");
                    location = "list.do";
                }
            },
            processData:false,
            contentType:false,
        })
    })
</script>
</html>
